﻿<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:helpers="clr-namespace:ToyundaPhone.Helpers"
	xmlns:converters="clr-namespace:ToyundaPhone.Converters"
	xmlns:controls="clr-namespace:ToyundaPhone.Controls"
	xmlns:SampleData="clr-namespace:Expression.Blend.SampleData.SongsDataSource" x:Name="userControl"
	mc:Ignorable="d"
	x:Class="ToyundaPhone.Controls.SongListControl"
	d:DesignWidth="456" d:DesignHeight="557">
	<UserControl.Resources>
		<Style x:Key="ListBoxItemWithNoSelectionStyle" TargetType="ListBoxItem">
			<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="ListBoxItem">
						<Border x:Name="LayoutRoot" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
							<VisualStateManager.VisualStateGroups>
								<VisualStateGroup x:Name="CommonStates">
									<VisualState x:Name="Normal"/>
									<VisualState x:Name="MouseOver"/>
									<VisualState x:Name="Disabled">
										<Storyboard>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="LayoutRoot">
												<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource TransparentBrush}"/>
											</ObjectAnimationUsingKeyFrames>
											<DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="ContentContainer"/>
										</Storyboard>
									</VisualState>
								</VisualStateGroup>
								<VisualStateGroup x:Name="SelectionStates">
									<VisualState x:Name="Unselected"/>
									<VisualState x:Name="Selected" />
								</VisualStateGroup>
							</VisualStateManager.VisualStateGroups>
							<ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
						</Border>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
		<Style x:Key="ImageButtonStyle" TargetType="Button">
			<Setter Property="Background" Value="Transparent"/>
			<Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/>
			<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
			<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/>
			<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="Button">
						<Grid Background="Transparent">
							<VisualStateManager.VisualStateGroups>
								<VisualStateGroup x:Name="CommonStates">
									<VisualState x:Name="Normal"/>
									<VisualState x:Name="MouseOver"/>
									<VisualState x:Name="Pressed">
										<Storyboard>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="fill">
												<DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
											</ObjectAnimationUsingKeyFrames>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="icon">
												<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneBackgroundBrush}"/>
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
									<VisualState x:Name="Disabled">
										<Storyboard>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="fill">
												<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
											</ObjectAnimationUsingKeyFrames>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Stroke" Storyboard.TargetName="border">
												<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
											</ObjectAnimationUsingKeyFrames>
											<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Fill" Storyboard.TargetName="icon">
												<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
											</ObjectAnimationUsingKeyFrames>
										</Storyboard>
									</VisualState>
								</VisualStateGroup>
							</VisualStateManager.VisualStateGroups>
							<Ellipse x:Name="fill" StrokeThickness="{StaticResource PhoneStrokeThickness}" Fill="{TemplateBinding Foreground}" Visibility="Collapsed"/>
							<Rectangle x:Name="icon" Height="48" Width="48" Fill="{StaticResource PhoneForegroundBrush}" OpacityMask="{TemplateBinding Background}"/>
							<Ellipse x:Name="border" Stroke="{TemplateBinding Foreground}" StrokeThickness="{StaticResource PhoneStrokeThickness}"/>
						</Grid>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
		<converters:VisibilityConverter x:Key="VisibilityConverter" />
		<helpers:HighlightStyle x:Key="HighlightStyle" Foreground="{StaticResource PhoneAccentBrush}" />
		<helpers:TextTokenizer x:Key="Tokenizer" />
		<DataTemplate x:Key="SongsItemTemplate">
			<Grid>
				<Grid.RowDefinitions>
					<RowDefinition/>
				</Grid.RowDefinitions>
				<Grid.ColumnDefinitions>
					<ColumnDefinition/>
					<ColumnDefinition Width="Auto"/>
				</Grid.ColumnDefinitions>
			<Grid Margin="{StaticResource PhoneVerticalMargin}">
				<Grid.RowDefinitions>
					<RowDefinition/>
					<RowDefinition/>
				</Grid.RowDefinitions>
				<Grid.ColumnDefinitions>
					<ColumnDefinition/>
					<ColumnDefinition Width="Auto"/>
				</Grid.ColumnDefinitions>
				<TextBlock Text="{Binding Title, Mode=OneTime}" helpers:HighlightText.Keywords="{Binding Search, ElementName=userControl}"
					helpers:HighlightText.Text="{Binding Title}" helpers:HighlightText.HighlightStyle="{StaticResource HighlightStyle}" 
					helpers:HighlightText.TextSplitter="{StaticResource Tokenizer}" helpers:HighlightText.WordExtractor="{StaticResource Tokenizer}" Grid.ColumnSpan="2" TextWrapping="Wrap"/>
				<TextBlock Text="{Binding Type}" Grid.Column="1" Grid.Row="1" Margin="12,0,0,0"/>
				<TextBlock Text="{Binding Work, Mode=OneTime}" helpers:HighlightText.Keywords="{Binding Search, ElementName=userControl}"
					helpers:HighlightText.Text="{Binding Work}" helpers:HighlightText.HighlightStyle="{StaticResource HighlightStyle}" 
					helpers:HighlightText.TextSplitter="{StaticResource Tokenizer}" helpers:HighlightText.WordExtractor="{StaticResource Tokenizer}" Grid.Row="1" TextWrapping="Wrap"/>
				</Grid>
				<Grid Grid.Column="1" VerticalAlignment="Center">
				<Grid.RowDefinitions>
					<RowDefinition/>
				</Grid.RowDefinitions>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto"/>
					<ColumnDefinition Width="Auto"/>
				</Grid.ColumnDefinitions>
				<Button Content="AddFav" Style="{StaticResource ImageButtonStyle}" Click="AddFavorite_Click" Grid.RowSpan="2" VerticalAlignment="Top" Visibility="{Binding Favorite, ConverterParameter=1, Converter={StaticResource VisibilityConverter}}" Margin="{StaticResource PhoneTouchTargetOverhang}" Grid.Column="1">
					<Button.Background>
						<ImageBrush Stretch="None" ImageSource="/ToyundaPhone;component/icons/appbar.favs.addto.rest.png"/>
					</Button.Background>
				</Button>
				<Button Content="RemFav" Style="{StaticResource ImageButtonStyle}" Click="RemFavorite_Click" Grid.RowSpan="2" VerticalAlignment="Top" Visibility="{Binding Favorite, Converter={StaticResource VisibilityConverter}}" Margin="{StaticResource PhoneTouchTargetOverhang}" Grid.Column="1">
					<Button.Background>
						<ImageBrush Stretch="None" ImageSource="/ToyundaPhone;component/icons/appbar.favs.removefrom.rest.png"/>
					</Button.Background>
				</Button>
				<Button Content="AddList" Grid.RowSpan="2" VerticalAlignment="Top" Style="{StaticResource ImageButtonStyle}" Click="AddList_Click" helpers:ListButtonVisibility.Playlist="{Binding Playlist, ElementName=userControl}" helpers:ListButtonVisibility.Trigger="{Binding PlaylistCount}" helpers:ListButtonVisibility.IsAdd="True" Margin="{StaticResource PhoneTouchTargetOverhang}">
					<Button.Background>
						<ImageBrush ImageSource="/ToyundaPhone;component/icons/appbar.lists.addto.rest.png" Stretch="None"/>
					</Button.Background>
				</Button>
				<Button Content="RemList" Grid.RowSpan="2" VerticalAlignment="Top" Style="{StaticResource ImageButtonStyle}" Click="RemList_Click" helpers:ListButtonVisibility.Playlist="{Binding Playlist, ElementName=userControl}" helpers:ListButtonVisibility.Trigger="{Binding PlaylistCount}" helpers:ListButtonVisibility.IsAdd="False" Margin="{StaticResource PhoneTouchTargetOverhang}">
					<Button.Background>
						<ImageBrush Stretch="None" ImageSource="/ToyundaPhone;component/icons/appbar.lists.removefrom.rest.png"/>
					</Button.Background>
				</Button>
				</Grid>
			</Grid>
		</DataTemplate>
		<SampleData:SongsDataSource x:Key="SongsDataSource" d:IsDataSource="True"/>
	</UserControl.Resources>
	<Grid d:DataContext="{Binding Source={StaticResource SongsDataSource}}">
		<StackPanel VerticalAlignment="Top" Visibility="{Binding Songs, ConverterParameter=1, Converter={StaticResource VisibilityConverter}}">
			<TextBlock Text="{Binding EmptyText, ElementName=userControl}" HorizontalAlignment="Center" Foreground="{Binding EmptyForeground, ElementName=userControl}" />
			<TextBlock TextWrapping="Wrap" Text="{Binding RefreshAlertText, ElementName=userControl}" Visibility="{Binding Search, ElementName=userControl, ConverterParameter=1, Converter={StaticResource VisibilityConverter}}" Margin="0,10,0,0"/>
		</StackPanel>
		<ListBox ItemTemplate="{StaticResource SongsItemTemplate}" d:DataContext="{Binding Source={StaticResource SongsDataSource}}" ItemsSource="{Binding Songs}" ItemContainerStyle="{StaticResource ListBoxItemWithNoSelectionStyle}" />
	</Grid>
</UserControl>